const pageLessPath = ['./pages/**/*.less']

const componentLessPath = ['./components/**/*.less']

const appLessPath = ['./app.less']

const gulp = require('gulp')
const less = require('gulp-less')
const plumber = require('gulp-plumber')
const rename = require('gulp-rename')
const replace = require('gulp-replace')

gulp.task('pageLess', () =>
  gulp
    .src(pageLessPath)
    .pipe(plumber())
    .pipe(less())
    .pipe(replace(/(\d+)px/g, (match, p1) => `${Number(p1) * 2}rpx`))
    .pipe(rename((path) => {
      path.extname = '.wxss'
    }))
    .pipe(gulp.dest('./pages')))

gulp.task('componentLess', () =>
  gulp
    .src(componentLessPath)
    .pipe(plumber())
    .pipe(less())
    .pipe(replace(/(\d+)px/g, (match, p1) => `${Number(p1) * 2}rpx`))
    .pipe(rename((path) => {
      path.extname = '.wxss'
    }))
    .pipe(gulp.dest('./components')))

gulp.task('appLess', () =>
  gulp
    .src(appLessPath)
    .pipe(plumber())
    .pipe(less())
    .pipe(replace(/(\d+)px/g, (match, p1) => `${Number(p1) * 2}rpx`))
    .pipe(rename((path) => {
      path.extname = '.wxss'
    }))
    .pipe(gulp.dest('./')))

gulp.task('style', () => {
  gulp.watch(pageLessPath, ['pageLess'])
  gulp.watch(componentLessPath, ['componentLess'])
  gulp.watch(appLessPath, ['appLess'])
})

// 启动  gulp syle
